﻿#region [ License information          ]
/* ************************************************************
 *
 * Copyright (c) Bjørn Bouet Smith, 2010, 2011
 *
 * This source code is subject to terms and conditions of 
 * Microsoft Public License (Ms-PL).
 * 
 * A copy of the license can be found in the license.txt
 * file at the root of this distribution. If you can not 
 * locate the License, please send an email to bjornsmith@gmail.com
 * 
 * By using this source code in any fashion, you are 
 * agreeing to be bound by the terms of the Microsoft 
 * Permissive License.
 *
 * You must not remove this notice, or any other, from this
 * software.
 *
 * ************************************************************/
#endregion

using System;
using System.ComponentModel;
using System.Configuration;

namespace Smith.AMC.Configuration
{
    /// <summary>
    /// Contains the configuration for the ServerNodeMonitor.
    /// </summary>
    public class ServerNodeMonitorConfiguration : ConfigurationElement
    {
        /// <summary>
        /// Holds the name of the config attribute that controls the interval between checking nodes that are dead and potentially dead.
        /// </summary>
        private const string CheckIntervalPropertyName = "checkinterval";

        /// <summary>
        /// Holds the name of the config attribute that controls the failed threshold.
        /// </summary>
        private const string FailedThresholdPropertyName = "failedthreshold";

        /// <summary>
        /// Gets or sets the threshold for when the server monitor should 
        /// start checking a MemcachedServerNode to see if its running or not.
        /// Any server node with a value in its FailedCount property above this value will be checked
        /// </summary>
        [ConfigurationProperty(FailedThresholdPropertyName, IsRequired = true, DefaultValue = 10)]
        [IntegerValidator(MinValue = 1, MaxValue = Int32.MaxValue)]
        public int FailedThreshold
        {
            get
            {
                return (int)this[FailedThresholdPropertyName];
            }

            set
            {
                this[FailedThresholdPropertyName] = value;
            }
        }

        /// <summary>
        /// Gets or sets the interval for how often the server monitor should 
        /// check a MemcachedServerNode to see if its running or not.
        /// </summary>
        [ConfigurationProperty(CheckIntervalPropertyName, IsRequired = true, DefaultValue = "00:00:10")]
        [TimeSpanValidator(MinValueString = "0:0:1")]
        [TypeConverter(typeof(TimeSpanConverter))]
        public TimeSpan CheckInterval
        {
            get
            {
                return (TimeSpan)this[CheckIntervalPropertyName];
            }

            set
            {
                this[CheckIntervalPropertyName] = value;
            }
        }
    }
}
